#ifndef YCBASETASKGROUP_H
#define YCBASETASKGROUP_H
#include "task.h"
#include <QList>

namespace yc {

class TaskGroup : public Task
{
    Q_OBJECT

public:
    TaskGroup(int id, bool auto_delete, int timeout, QObject* parent = nullptr);
    TaskGroup(int parallel_count, int id, bool auto_delete, int timeout, QObject* parent = nullptr);
    ~TaskGroup();

    void setIgnoreErrors(bool ignore_errors) { ignore_errors_ = ignore_errors; }
    void setKeepRunning(bool keep) { keep_running_ = keep; }
    int parallelCount() const { return parallel_count_; }
    int waitingCount() const { return waiting_tasks_.size(); }
    void addTask(Task* task, bool at_end = true);
    void terminateTask(int id);
    void terminateTasks();

private:
    void startImpl() override;
    void terminateImpl() override;
    void startNextTask();
    void removeTask(Task* task);

    bool ignore_errors_ = false;
    bool keep_running_ = false;
    int parallel_count_;
    QList<Task*> waiting_tasks_;
    QList<Task*> running_tasks_;
};

} // namespace yc

#endif // YCBASETASKGROUP_H
